package com.xrit.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.constant.MessageConstant;
import com.xrit.sunnyday.entity.Result;
import com.xrit.sunnyday.pojo.Setmeal;
import com.xrit.sunnyday.service.SetMealMobileService;
import com.xrit.sunnyday.utils.QiNiuUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类名称: SetMealMobileController
 * 类描述:TODO
 * 创建人: czb
 * 创建时间:2022/5/23 下午 04:48
 * Version 1.0.0
 */
@RestController
@RequestMapping("/setmeal")
public class SetMealMobileController {
    @Reference
    private SetMealMobileService setMealMobileService;

    /**
     * @description: 查询套餐
     * @param:
     * @return: com.xrit.sunnyday.entity.Result
     * @author czb20
     * @date: 下午 04:36
     */
    @GetMapping("/getSetmeal")
    public Result getSetMealList() {
        List<Setmeal> list = setMealMobileService.findAll();
        list.forEach(setmeal -> {
            setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        });
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, list);
    }

    /**
     * @description: 查询套餐详情
     * @param: id
     * @return: com.xrit.sunnyday.entity.Result
     * @author czb20
     * @date: 下午 04:35
     */
    @GetMapping("/findDetailById")
    public Result findDetailById(int id) {
        Setmeal setmeal = setMealMobileService.findDetailById(id);
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
    }

    @PostMapping("/findById")
    public Result findById(Integer id) {
        Setmeal setmeal = setMealMobileService.findById(id);
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        System.out.println(setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);

    }
}
